﻿/*  ----------------------------------------------------------------------------
 *  DES-Release 2
 *  ----------------------------------------------------------------------------
 *  File:       Form1.cs
 *  Author:     nitinkoshy@gmail.com
 *  Source:     http://des.codeplex.com/
 *  ----------------------------------------------------------------------------
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DES.Common;
using System.ServiceModel;
using DES.Test.SimpleTest;
using System.Reflection;
using System.IO;
using System.Messaging;
using System.Security.Principal;
using DES.Task.Basic;


namespace DES.Test.SimpleTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            for (int numberOfRequest = 0; numberOfRequest < nudRequests.Value; numberOfRequest++)
                SimulateRequest();
        }

        private void SimulateRequest()
        {
            ChannelFactory<IDESService> desServiceFactory = new ChannelFactory<IDESService>(new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:800/DESService"));

            IDESService desService = desServiceFactory.CreateChannel();


            Type type = new AddNumbersTask().GetType();
            Assembly assembly = Assembly.GetAssembly(type);
            byte[] assemblyBytes = File.ReadAllBytes(assembly.Location);


            ClientTask clientTask = new ClientTask();
            clientTask.TypeName = type.FullName;
            clientTask.CanExecuteIndependently = true;
            //clientTask.AssemblyBytes = assemblyBytes;
            clientTask.AssemblyFileLocation = @"D:\Work\MSCS\Project\DES\Tasks\DES.Task.Basic\bin\Debug\DES.Task.Basic.dll";
            clientTask.AssemblyName = "DES.Test.Basic";
            clientTask.Id = Guid.NewGuid();

            clientTask.EndPoint = ".\\private$\\ResultQueue-App-A";

            if (rbAdmin.Checked)
                clientTask.Credential = new Credential("nitinstephen_koshy", "CISCO7941s8r18s", "itlinfosys");
            else
                clientTask.Credential = new Credential("tester", "W1nd0w*V1*ta", "blrkec37146l");
            
            desService.ProcessTask(clientTask);

            desServiceFactory.Close();

        }

        
    }
}
